package com.hy.study.driver;

import com.hy.study.bean.SortFlowBean;
import com.hy.study.mapper.SortFlowCountMapper;
import com.hy.study.partition.SortProvincePartitioner;
import com.hy.study.reduce.SortFlowCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * 对上次计算的输出结果在一次进行加工处理 全排序
 *
 * @author huyong
 * @date 2024 年 02 月 05 日 15:36: 57
 */
public class SortFlowCountDriver {
    public static void main(String[] args) throws Exception {
        final String inputfile = "F:\\study\\Hadoop\\output\\phone_result";
        final String outputfile = "F:\\study\\Hadoop\\output\\phone_result4";
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(SortFlowCountDriver.class);

        job.setMapperClass(SortFlowCountMapper.class);
        job.setReducerClass(SortFlowCountReducer.class);

        job.setMapOutputKeyClass(SortFlowBean.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(SortFlowBean.class);

        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        // 关联分区
        job.setPartitionerClass(SortProvincePartitioner.class);
        // 设置输出分区个数
        job.setNumReduceTasks(5);

        boolean completion = job.waitForCompletion(true);

        System.exit(completion ? 0 : 1);


    }
}
